package com.gancp.jms.impl;

import com.gancp.common.constants.Constants;
import com.gancp.common.constants.Parmeters;
import com.gancp.jms.IConsumer;
import com.gancp.service.SendMessage;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

/**
 * @Author gancp
 * @Date 时间被黑洞吸走了
 * @Descripition 消息队列-消费者
 **/
@Slf4j
@Component
public class Consumer implements IConsumer {

    @Autowired
    private SendMessage sendMessage;

    /**
     * @Author gancp
     * @Date 时间被黑洞吸走了
     * @Descripition 动态使用配置文件中消息队列名称
     **/
    @JmsListener(destination = "${miaodiMsg.Queue}")
    @Override
    public void receiveQueue(String message) {
        if (StringUtils.isEmpty( message )) {
            return;
        }
        try {
            // 发送短信
            String phone = message.split( Constants.PHONE_VERIFVCODE_SPLIT )[0];
            String verifvCode = message.split( Constants.PHONE_VERIFVCODE_SPLIT )[1];
            sendMessage.sendVerifvCode( phone, verifvCode );
        } catch (Exception e) {
            log.error( "发送短信验证码失败，手机号和验证码信息" + message, e );
        }
    }

}
